import logging
import os
import time

current_path=os.path.dirname(__file__)
log_path=os.path.join(current_path,'..','logs')
class LogUtils:
    def __init__(self,logpath=log_path):
        self.log_file_path=os.path.join(logpath,'WX_API_LOG_%s'%time.strftime('%Y%m%d'))
        self.loger = logging.getLogger("微信公众号接口测试")
        self.loger.setLevel(logging.DEBUG)

        self.consle_handler = logging.StreamHandler()
        self.file_handler = logging.FileHandler(self.log_file_path,'a',encoding='utf-8')

        fomate_log=logging.Formatter("%(asctime)s__%(name)s__%(levelname)s__%(message)s")

        self.consle_handler.setFormatter(fomate_log)
        self.file_handler.setFormatter(fomate_log)

        self.loger.addHandler(self.consle_handler)
        self.loger.addHandler(self.file_handler)

        self.consle_handler.close()
        self.file_handler.close()
    def get_log(self):
        return self.loger

logger=LogUtils().get_log()

if __name__ == '__main__':
   # logger=LogUtils().get_log()
   # logger.info('hehheha ')
   logger.info('测试哈哈哈')